<#include "../menu.html.ftl">
<html>
 <head> 
	<title>V&auml;stra G&ouml;talandsregionen - Mina listor</title>
   	<link rel="stylesheet" type="text/css" href="/alfresco/css/vgr/createsearch.css" />
   	<script type="text/javascript" src="/alfresco/scripts/jquery/jquery.js"></script>
   	
</head>
 <body class="yui-skin-sam">
 
	<div class="Container">
	 <div class="first_header">
	 	Mina listor
 	 </div>
	<@menu/> 
	<div id="content">
 	 	<div class="VGMainBorder" style="clear: both;">
	 	 	<div class="VGCell">
 			<h2>Mina listor</h2>
 				<#list lists as list>
	 				<p><a href="#" onclick="show_list('${list.properties.name}'); return false;">${list.properties.name}</a></p>
	 			</#list>
	 		</div>
 	 	</div>
 	 
 	 	<div id="list-content" style="display:none;">
 	 		<p id="list-name"></p>
 	 		
 	 		<div id="menu" style="display:none;"></div>
 	 		<div id="list"></div>
 	 	</div>
 	 </div>
 	</div>
</body>

<script type="text/javascript">
	function show_list(name) {
		$("#list-content").show();
		$.ajax({type: "GET",
		url: "/alfresco/service/vgr/resultlist?name=" + name + "&format=html",
		success: function(data) {
			$("#list-name").html("<h1>Visar listan " + name + "</h1>");
			build_list_menu(name);
     		$("#list").replaceWith("<div id='list'>" + data + "</div>");
  		}
		});
	}
	
	function build_list_menu(name) {
		html  = "<div id='menu'>";
		html += "<a href='/alfresco/service/vgr/search?name=" + name + "'>redigera</a> | ";
		html += "<a href='#' onclick=\"delete_list('" + name +"'); return false;\" >ta bort</a> | ";
		html += "<a href='/alfresco/service/vgr/resultlist?name=" + name + "&format=html'>html</a> | ";
		html += "<a href='/alfresco/service/vgr/resultlist?name=" + name + "&format=xml'>xml</a> | ";
		html += "<a href='/alfresco/service/vgr/resultlist?name=" + name + "&format=rss'>rss</a>";
		html += "</div>";
		
		$("#menu").replaceWith(html);
		$("#menu").show();
	}
	
	function delete_list(name) {
		if (confirm("Är du säker på att du vill ta bort listan " + name)) {
			$.ajax({type: "POST",
				url: "/alfresco/service/vgr/search?name=" + name + "&alf_method=DELETE",
				async: false
			})
			
			window.location.reload();
		}
	}
</script>
</html>